package com.tr.rentcar.model.dao;

import java.sql.SQLException;
import java.util.Map;

import com.tr.rentcar.model.GlobalParamHandler;
import com.tr.rentcar.model.bean.OrderNo;
import com.tr.rentcar.model.jdbc.MySqlDb;
import com.tr.rentcar.model.jdbc.ResultHandler;

public class OrderNoDao implements ResultHandler<OrderNo> {
	
	MySqlDb db=MySqlDb.getInstance();

	@Override
	public OrderNo doHander(Map<String, Object> row) {
		OrderNo on=new OrderNo();
		on.setOnid(Integer.parseInt(row.get("onid")+""));
		return on;
	}
	/**
	 * 获取最后的数据
	 * @return
	 * @throws SQLException
	 */
	public Integer getNo() throws SQLException{
		String sql="select max(onid) from order_no";
		return (Integer) db.executeCountQuery(sql);
	}
	/**
	 * 插入新的数据
	 * @param no
	 * @return
	 * @throws SQLException
	 */
	public boolean insertNo(int no) throws SQLException{
		String sql="insert into order_no values(?)";
		return db.executeUpdate(sql, new GlobalParamHandler(no))>0;
	}

}
